﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;

namespace MedicWeb.forms.Settings {
    public partial class MainSettings : SessionPage {
        private MedicService.Settings settings;
        protected void Page_Load(object sender, EventArgs e) {
            var mainService = new MainService();
            settings = mainService.GetSettings(GetSession());
            if (!IsPostBack) {
                tbAlertTime.Text = "" + settings.AlertTime;
                tbNumber.Text = "" + settings.NextNumber;
            }
        }

        protected void Button1_Click(object sender, EventArgs e) {
            string time = Regex.Replace(tbAlertTime.Text, "\\D", "");
            string number = Regex.Replace(tbNumber.Text, "\\D", "");
            settings.AlertTime = int.Parse(time);
            settings.NextNumber = int.Parse(number);
            var mainService = new MainService();
            mainService.SaveSettings(GetSession(), settings);
        }
    }
}